home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / mdxget.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  7KB  |  325 lines

  1. #include    "multix.h"
  2.  
  3. #include    <stdio.h>
  4. #include    <stdlib.h>
  5.  
  6. #include    <string.h>
  7. #include    <time.h>
  8.  
  9.  
  10. #include    "appl.h"
  11. TMdxProcId        MyId;
  12. Int8            SourceFile[25];
  13. Int8            TargetFile[25];
  14. Int8            ServerName[25];
  15. TFileTransferInfo    FtpFileInfo;
  16.  
  17. TResult SetFtpMsg(
  18. Int8Ptr    Source,
  19. Int8Ptr Target
  20. )
  21. {
  22.     memset(&FtpFileInfo,0,sizeof(FtpFileInfo));
  23.  
  24.     strcpy(FtpFileInfo.SrcFileName,Source);
  25.     strcpy(FtpFileInfo.TgtFileName,Target);
  26.  
  27.     return(Success);
  28.  
  29. }
  30.  
  31.  
  32. void    ApplPutFile(
  33. TMdxSRMsgInfo  *MsgInfo
  34. )
  35. {
  36.     TFileTransferInfo    FileInfo;
  37.     FILE    *File;
  38.  
  39.  
  40.     MdxMsgRead(MsgInfo->Received.Msg,&FileInfo,sizeof(FileInfo));
  41.  
  42.  
  43.     printf("(%ld)File %s ( Size = %ld)Received and ",MdxGetCurrTimerValue(),
  44.                                                     FileInfo.TgtFileName,
  45.                                                     MdxMsgSizeGet(MsgInfo->Received.Msg)-sizeof(FileInfo)
  46.                                                     );
  47.  
  48.     File    =    fopen(FileInfo.TgtFileName,"wb");
  49.     if ( (File) == (void *)0 )
  50.     {
  51.         printf("Failed Creating It\n");
  52.     } else
  53.     {
  54.         TBufSize    CountRead;
  55.         UInt8        Buf[500];
  56.         while (    (CountRead    =    MdxMsgRead(    MsgInfo->Received.Msg,
  57.                                                 Buf,
  58.                                                 sizeof(Buf)
  59.                                                 ))    >    0    )
  60.         {
  61.             if (    fwrite(Buf,1,CountRead,File)    !=    CountRead    )
  62.             {
  63.                 fclose(File);
  64.                 remove(FileInfo.TgtFileName);
  65.                 printf("Failed Storing It\n");
  66.                 return;
  67.             }
  68.         }
  69.         fclose(File);
  70.         printf("stored Successfuly\n");
  71.     }
  72. }
  73.  
  74.  
  75. void    ApplDataReplyReceived(
  76. TMdxEvent    *Event
  77. )
  78. {
  79.     TMdxSRMsgInfo    *MsgInfo;
  80.  
  81.     /*
  82.     "Event->Data"    holds the information abount the new message.
  83.     */
  84.  
  85.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  86.  
  87.     /*    First    thing is to check MsgCode of the new message    */
  88.  
  89.     switch(MsgInfo->Received.MsgCode)
  90.     {
  91.         case    ApplGetFileMsgCode    :
  92.         {
  93.             ApplPutFile(MsgInfo);
  94.             ApplShutdown    =    True;
  95.         }
  96.         break;
  97.         default                     :    break;
  98.     }
  99. }
  100.  
  101. void    ApplSendGetFileReq(
  102. TMdxProcId    ProcId
  103. )
  104. {
  105.     TMdxError    Result;
  106.     Result    =    MdxSendData( ProcId,
  107.                                 &FtpFileInfo,                    /*    Msg                */
  108.                                 sizeof(FtpFileInfo),
  109.                                 ApplGetFileMsgCode,    /*    Msg Code        */
  110.                                 10,                        /*    Lowest Priority    */
  111.                                 MdxSendReliable,        /*    Send Attributes    */
  112.                                                         /*    Success/Failure    */
  113.                                                         /*    Report            */
  114.                                 0,                        /*    No ReqSeq        */
  115.                                 12000                    /*    10 Secs Timeout    */
  116.                                                         /*    for the other side*/
  117.                                                         /*    to confirm message*/
  118.                                 );
  119.     if (    Result    !=    MdErrNoError    )
  120.     {
  121.         printf("(%ld) Send Req Failed With Error - %d\n",
  122.                 MdxGetCurrTimerValue(),Result);
  123.  
  124.     }
  125. }
  126.  
  127.  
  128.  
  129. void    ApplInitReceived(void)
  130. {
  131.     TMdxProcessParams    ProcessParams;
  132.     TMdxLinkParams    LinkParams;
  133.  
  134.     /*
  135.     You may choose to use onw or more links of the types specified.
  136.     Un comment the relevent "MdxOpenLink()".
  137.  
  138.     You may change the parameters for the links.
  139.     */
  140.  
  141.  
  142.     memset(&LinkParams,0,sizeof(LinkParams));
  143.     strcpy(LinkParams.LinkName.Byte,"com2");
  144.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  145.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  146.     LinkParams.ConnectTimeout        =    0x7fffffff;
  147.     LinkParams.MaxConnectRetries    =    -1;
  148.     LinkParams.ConnectRetriesDelay    =    200;
  149.     LinkParams.LinkBaud             =    19200;
  150.     LinkParams.UseDlcFraming        =    True;
  151.     LinkParams.ImAliveInterval        =    400l;
  152.     LinkParams.MaxPollRetries        =    2;
  153.     LinkParams.L1MaxSendSize        =    256;
  154.     /*
  155.     MdxOpenLink(&LinkParams);
  156.     */
  157.     memset(&LinkParams,0,sizeof(LinkParams));
  158.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  159.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  160.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  161.     LinkParams.ConnectTimeout        =    1000;
  162.     LinkParams.MaxConnectRetries    =    -1;
  163.     LinkParams.ConnectRetriesDelay    =    200;
  164.     LinkParams.UseDlcFraming        =    True;
  165.     LinkParams.MaxPollRetries        =    10;
  166.     LinkParams.L1MaxSendSize        =    500;
  167.     /*
  168.     MdxOpenLink(&LinkParams);
  169.     */
  170.  
  171.     memset(&LinkParams,0,sizeof(LinkParams));
  172.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  173.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  174.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  175.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  176.     LinkParams.ConnectRetriesDelay    =    300l;
  177.     LinkParams.L1MaxSendSize        =    1024;
  178.     LinkParams.MaxConnectRetries    =    -1l;
  179.     /*
  180.     MdxOpenLink(&LinkParams);
  181.     */
  182.  
  183.  
  184.     memset(&ProcessParams,0,sizeof(ProcessParams));
  185.     ProcessParams.ProcId                    =    CallId;
  186.     ProcessParams.InactivityTimer            =    6000;
  187.     ProcessParams.ConnectRetriesInterval    =    200;
  188.     MdxConnectProcess(&ProcessParams);
  189.     printf("(%ld) Calling %ld\n",MdxGetCurrTimerValue(),ProcessParams.ProcId);
  190.     ApplSendGetFileReq(CallId);
  191. }
  192.  
  193.  
  194. void    ApplSendMsgCompleted(
  195. TMdxEvent    *Event
  196. )
  197. {
  198.     TMdxSRMsgInfo        *MsgInfo;
  199.     TFileTransferInfo    FileInfo;
  200.  
  201.     /*
  202.     "Event->Data"    holds the information abount the Message we sent.
  203.     */
  204.  
  205.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  206.     switch(MsgInfo->Sent.MsgCode)
  207.     {
  208.         case    ApplGetFileMsgCode    :
  209.         {
  210.             MdxMsgRead(MsgInfo->Sent.Msg,(UInt8Ptr)&FileInfo,sizeof(FileInfo));
  211.             printf("Get File (%s):%s To %s  ",
  212.             ServerName,
  213.             FileInfo.SrcFileName,
  214.             FileInfo.TgtFileName);
  215.             printf("Failed : Error = %d\n",Event->Error);
  216.             ApplShutdown    =    True;
  217.         }
  218.         break;
  219.         default                     :    break;
  220.     }
  221. }
  222.  
  223.  
  224. void    ApplCallCompleted(
  225. TMdxEvent    *Event
  226. )
  227. {
  228.     printf("(%ld) Call Completed to Process (%ld)\n",
  229.             MdxGetCurrTimerValue(),Event->ProcId);
  230. }
  231.  
  232.  
  233. void    cdecl    ApplEventHandler(
  234. TMdxEvent    *Event
  235. )
  236. {
  237.     switch(Event->Code)
  238.     {
  239.         case    MdxEvCallCompleted            :
  240.         case    MdxEvCallRejected            :
  241.         {
  242.             ApplCallCompleted(Event);
  243.         }
  244.         break;
  245.         case    MdxEvSendMsgCompleted        :
  246.         {
  247.             ApplSendMsgCompleted(Event);
  248.         }
  249.         break;
  250.         case    MdxEventApplInit                :
  251.         {
  252.             ApplInitReceived();
  253.         }
  254.         break;
  255.         case    MdxEvDataReplyReceived        :
  256.         {
  257.             ApplDataReplyReceived(Event);
  258.         }
  259.         break;
  260.         case    MdxStdInAvailable                :
  261.         {
  262.             ApplShutdown    =    True;
  263.         }
  264.         break;
  265.         default                                 :    break;
  266.     }
  267. }
  268.  
  269.  
  270. Int cdecl    main(
  271. Int     Argc,
  272. Int8Ptr *Argv
  273. )
  274. {
  275.     TSIndex CallIndex;
  276.     MyId    =    9999998;
  277.     if (    Argc    <    3    )
  278.     {
  279.         printf("Usage : mdxget SourceFile [TargetFile] <Node Id To Call>\n");
  280.         return(5);
  281.     }
  282.  
  283.     strcpy(SourceFile,Argv[1]);
  284.     if (    Argc    >    3    )
  285.     {
  286.         strcpy(TargetFile,Argv[2]);
  287.         CallIndex    =    3;
  288.     } else
  289.     {
  290.         strcpy(TargetFile,SourceFile);
  291.         CallIndex    =    2;
  292.     }
  293.     if ( (getenv(Argv[CallIndex])) != (void *)0 )
  294.     {
  295.         CallId    =    atol(getenv(Argv[CallIndex]));
  296.         strcpy(ServerName,getenv(Argv[CallIndex]));
  297.     } else
  298.     {
  299.         CallId    =    atol(Argv[CallIndex]);
  300.         strcpy(ServerName,Argv[CallIndex]);
  301.     }
  302.  
  303.     if (    CallId    ==    0    )
  304.     {
  305.         printf("Invalid Value For Id To Call\n");
  306.         exit(0);
  307.     }
  308.  
  309.  
  310.     MultiXStart(MyId,"Mdx File Copy",0,ApplEventHandler);
  311.  
  312.     if (    SetFtpMsg(SourceFile,TargetFile)    !=    Success )
  313.     {
  314.         printf("Invalid File To Copy\n");
  315.         exit(0);
  316.  
  317.     }
  318.     printf("Type any key to stop the program...\n");
  319.     while (    ApplShutdown    ==    False    )
  320.     {
  321.         MultiXWaitEvent();
  322.     }
  323.     return(0);
  324. }
  325.